<?php
/**
 * Created by PhpStorm.
 * User: Victor
 * Date: 2018/11/6
 * Time: 14:21
 */
    header('Content-Type:text/html;charset=utf-8');
    if(!defined('ROOT_PATH')){
        define('ROOT_PATH', dirname(__FILE__));
    }
    require(ROOT_PATH."/define.php");
    include "phpqrcode/phpqrcode.php";
    $a = file_get_contents('php://input');
    //var_dump($a);die();
    if (!isset($a)){
        die('error:未传参数或参数格式有误！');
    }
    $a  = json_decode($a,true);
   // $a = $a['json'];
    //var_dump($a);die();
    if(isset($a)){
        $sql = '';
        foreach($a as $k => $v){
            //处理单条数据
            $b = $v['value'];
            $c = explode(' ',$b);
            if(count($c) == 15 ){
                //有内容
                for ($i=0;$i<15;$i++){
                    if($c[$i]==''){
                        $c[$i] = '暂无数据';
                    }
                    if($i==3){
                        $time = strtotime($c[3].' '.$c[4]);
                        $str = $str . '"'.$time.'",';
                        continue;
                    }elseif ($i==4){
                        continue;
                    }
                    $str .= '"'.$c[$i].'",';
                }
                $str  = substr($str,0,-1);
                $sql .= "INSERT INTO iw_test (order_num,shop_num,shop_name,jiaoyi_time,ys_jine,content,yh_jine,sh_jine,tk_jine,sxf,js_jine,order_lb,order_status,caozuo) VALUES (".$str.");";
                unset($str);
            }else{
                //无内容
                die("数据类型有误");
            }

        }
        $sql = substr($sql,0,-1);
    }
    //echo $sql;die();
    //验证身份
//    if(empty($_POST['username']) and empty($_POST['password'])){
//        die("错误:参数错误(不全或格式有误)!");
//    }
    //获取数据（post）
    //$data = send_post($shuju_url);
//    if (empty($data)){
//        die("错误:请求数据返回有误！");
//    }
    //print_r($data);die();
    //连接数据库
    $db = new mysqli($db_host_cs, $db_user_cs, $db_pass_cs, $db_name_cs);
    //连接数据库判断
    if ($db->connect_error) {
        die("连接失败: " . $db->connect_error);
    }
//    $cars = array
//        (
//            array("name"=>"Volvo","phone"=>100,"createtime"=>121),
//            array("name"=>"BMW","phone"=>60,"createtime"=>122),
//            array("name"=>"Toyota","phone"=>110,"createtime"=>1899)
//        );
//    if(isset($cars)){
//        $sql = 'INSERT INTO iw_admin (username, phone ,createtime) VALUES ';
//        foreach($cars as $k => $v){
//        $sql .= "('$v[name]','$v[phone]','$v[createtime]'),";
//        }
//        $sql = substr($sql,0,-1);
//    }
if ($db->multi_query($sql) === TRUE) {
    echo "新记录插入成功";
} else {
    echo "Error: " . $sql . "<br>" . $db->error;
}
    die();
   // $sql = "INSERT INTO iw_test (order_num) VALUE ('$a')";
    $insert_bz = $db->query($sql);
    if (!$insert_bz) {
        die("新记录插入失败: " . $db->error);
    }
    //echo "新记录插入成功,插入主键ID为：".$db->insert_id;
    //制作二维码
    $errorLevel = "L";
    $size = "4";
    $url= $tiao_url;
    $url= $tiao_url.'tiaozhuan.php?id='.$db->insert_id;
    $QR = QRcode::png($url, false, $errorLevel, $size);
    imagepng($QR, 'helloweba.png');
    echo '<img src="helloweba.png">';


